
// 新增页面保存逻辑

import {
    toast
} from 'nc-lightapp-front';

import saveNewPerson2 from '../request/savePersonInfo2';

import language from '../../../language';

const formLists = ['bd_psndoc', 'hi_psnjob_h', 'hi_psnorg_h'];

import init from './init';

export default async function(postData) {
    try {
        let res = await saveNewPerson2(postData);

        const {
            button,
            form,
            pageFrom,
            selectedRows
        } = this.props;
        const pk_psnjob = this.state.pk_psnjob
        if(res.success) {
            if(res.data.errMsg){
                toast({
                    color: 'danger',
                    content: res.data.errMsg
                });
                if(res.data.newPsnCode) {
                    selectedRows[0].data.values['pk_psndoc.code'] = {
                        display: res.data.newPsnCode,
                        value: res.data.newPsnCode
                    };
                    form.setFormItemsValue('bd_psndoc', {
                        code: {
                            display: res.data.newPsnCode,
                            value: res.data.newPsnCode
                        }
                    });
                }
                if(res.data.newClerkCode) {
                    selectedRows[0].data.values['clerkcode'] = {
                        display: res.data.newClerkCode,
                        value: res.data.newClerkCode
                    };
                    form.setFormItemsValue('hi_psnjob_h', {
                        clerkcode: {
                            display: res.data.newPsnCode,
                            value: res.data.newPsnCode
                        }
                    });
                }
                return;
            }
            toast({
                color: 'success',
                content: pageFrom === 'add' ? language['hi6007-000035'] : language['hi6007-000036']/* 国际化处理： 新增成功,修改成功*/
            });
            this.props.getModifyData((res) => {
                init.call(this, true);
                this.props.cancelEdit();
            }, res.data['pk_psnjob'], 'refresh'); //
            

            // this.props.getModifyData(() => {
            //     init.call(this, true);
            //     this.props.cancelEdit();
            // }, res.data['pk_psnjob']);

            // this.props.toEditPage('dbClick', () => {}, pk_psnjob) 
        }
    }
    catch(e) {
    }
}
